package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable("type") Integer type){
        return Result.success(activityService.getByType(type));
    }


    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        activityService.updateActivity(activity);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        return Result.success(activityService.getById(id));
    }


    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        activityService.deleteById(id);
        return  Result.success();
    }


    @PostMapping
    public Result addActivity(@RequestBody Activity activity) {
        activityService.addActivity(activity);
        return Result.success();
    }


    @GetMapping
    public Result list(ActivityDTO activityDTO) {
        return Result.success(activityService.list(activityDTO));
    }
}
